clear all

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/

capture log close

log using "log/POBE_final_appendix_E", replace text

set maxvar 15000


cd /home/almdan/EoC/analysis/revising_citizenship/

use "data/finaldata_revising_citizenship", clear

set more off

keep lopnr btkdpos3 base_inry_year utan_coherent inrar insk_date_sif insk_quart_sif stserv org1 complserv_ch FB2004_coh_ver2 mof_year finish_high_sch moth_schyrs_mod fath_schyrs_mod log_fath_ave_defl_totinc_C log_moth_ave_defl_totinc_C foreign muskkap hals_1-hals_7 perfsight synkap perfhear fyskap lngd mass bodymass intr gkap gvkap gckap pf donor_2230 numb_donor_2230  kund_rtjanst_2015 bet_rtjanst_2015 kund_rtjanst_2016 bet_rtjanst_2016 bethushall_rtjanst_2015 bet_bethushall_rtjanst_2015 bethushall_rtjanst_2016 bet_bethushall_rtjanst_2016 bet_rtjanst kund_el_hush_rtjanst_2015 bet_kund_el_hush_rtjanst_2015 k l r any_vote mof_year mof_date_sif civserv_inskr old20 age_mof_year foreign school_lev6_bef30 lan_trm fodelsear_mof fodelsear inrk mof_month_sif btkd*

*************************************************************
** Merging election 2010 data **
*************************************************************
rename lopnr LopNr
** Change Direcotry **
cd /home/almdan/CMC/

merge 1:1 LopNr using "build/normdata/valdata2010.dta", keepusing(r_2010 l_2010 k_2010 Rostratt_2010) generate(merge_val2010)


drop if merge_val2010==2

** Gen any vote **

gen any_vote_2010=1 if (r_2010==1 | l_2010==1 | k_2010==1)

replace any_vote_2010=0 if any_vote_2010==.

replace any_vote_2010=. if (r_2010==. | l_2010==. | k_2010==.)

label var any_vote_2010 "Voted, Any (2010)"


label values any_vote_2010 rost

tab r_2010
tab l_2010
tab k_2010 

tab any_vote_2010

tab r_2010 any_vote_2010
tab l_2010 any_vote_2010
tab k_2010 any_vote_2010

count if r_2010==.
count if l_2010==.
count if k_2010==.
count if any_vote_2010==.

*************************************************************
** Merging election 2018 data. the 2021 data**
*************************************************************
** Change Direcotry **
cd /home/almdan/CMC/

merge 1:1 LopNr using "build/normdata/valdata2018_2.dta", keepusing(r_2018 l_2018 k_2018 Rostratt_2018) generate(merge_val2018)


drop if merge_val2018==2

** Gen any vote **

gen any_vote_2018=1 if (r_2018==1 | l_2018==1 | k_2018==1)

replace any_vote_2018=0 if any_vote_2018==.

replace any_vote_2018=. if (r_2018==. | l_2018==. | k_2018==.)

label var any_vote_2018 "Voted, Any (2018)"


label values any_vote_2018 rost

tab r_2018
tab l_2018
tab k_2018 

tab any_vote_2018

tab r_2018 any_vote_2018
tab l_2018 any_vote_2018
tab k_2018 any_vote_2018

count if r_2018==.
count if l_2018==.
count if k_2018==.
count if any_vote_2018==.

********************************************************************************
*** Create Service variable ***
********************************************************************************

cd /home/almdan/CMC/build/
rename LopNr lopnr
merge 1:1 lopnr using "temp/gu_data_pliktverket_2021_temp", keepusing(org1_ny2021) generate(pliktverket_test)

drop if pliktverket_test==2

********************************************************************************

gen stserv_ny2021=1 if org1_ny2021!=.
replace stserv_ny2021=0 if stserv_ny2021==.
label variable stserv_ny2021 "Started service ny2021"

********************************************************************************
*** Adjusting schoolyears ***
********************************************************************************
replace moth_schyrs_mod=7 if moth_schyrs_mod==6

replace fath_schyrs_mod=7 if fath_schyrs_mod==6

***************************************************
*** From the NSA test and military service data ***
***************************************************
*** btkd = military occupation code (e.g. xxyyy where x is a letter and y is a number)
*** inrk = test office
*** civserv_inskr = conscripted into civil service (first position in btkd=Q)
*** utan = code for military unit
*** utan_coherent = code for military unit, harmonized across years
*** old20 = indicating wheter a conscript is planned to enter service later that age 20 (inrar - birth year (fodelsear) obtained from SCB)
*** base_inry_year = interaction of inrar and utan_coherent
*** insk_date = date conscripted
*** mof_date_sif = date tested
*** mof_month_sif = test month 
*** insk_quart_sif = quarter of the year when conscripted
*** org1 = The unit in which the conscript entered service (The military service data. Only those who enter service ha an entry in this data set)
*** complserv_ch = indicating whether completed service (defined by receiving grades in the military data)
*** FB2004_coh_ver2 = indicating whether conscript is assigned to a closed unit in 2005 or 2006
*** FB2004_coh_ver2 is defined and created when building the current data set by using the code (what units is described in Ministry of Defence 2004c (see reference list)):

/*
#delimit;
gen FB2004_coh_ver2 = 1 if inrar >= 2005 & insk_date_sif < td(23sep2004) & (
utan_coherent==13 	
| utan_coherent==11 	
| utan_coherent==12	
| utan_coherent==31	
| utan_coherent==28 	
| utan_coherent==24 	
| utan_coherent==25 	
| utan_coherent==23 	
| utan_coherent==37 	
| utan_coherent==26 	
| utan_coherent==16 	
| utan_coherent==17 	
| utan_coherent==18 	
| utan_coherent==19 	
| utan_coherent==3);	

#delimit cr

replace FB2004_coh_ver2=0 if FB2004_coh_ver2==.

label variable FB2004_coh_ver2 "Closed Base"
label values FB2004_coh_ver2 yesno

*/
*** mof_year = test year
*** age_mof_year = age at test year (mof_year - birth year (fodelsear) obtained from SCB)
*** fodelsear_mof = birth year 
*** muskkap = muscle capacity
*** hals1 - hals7 = health category dummies
*** synkap = sight capacity
*** perfhear = hearing capacity
*** fyskap = physical cpacity
*** lngd = height
*** mass = weight
*** bodymass = body mass index (BMI)
*** intr = motivation indicated at the interview
*** gkap = cognitive ability
*** gckap = spatial ability
*** gvkap = verbal ability
*** pf = psychological capacity
*** stserv_ny2021 = indicating wheter individual entered service

******************************
*** From Statistics Sweden ***
******************************
*** foreign = foreign background by SCB definition  (computed from utlsvbakgr (LISA register))
*** moth_schyrs_mod = years of schooling mother (computed from SUN2000nivaold (LISA register))
*** fath_schyrs_mod = years of schooling father (computed from SUN2000nivaold (LISA register))
*** finished high school = indicating whether graduated from high school (education register from SCB)
*** school_lev6_bef30 = indicating wheter at least three years of post secondary education before age 30 (computed from SUN2000nivaold (LISA register))
*** fodelsear = birth year (RTB-register from SCB)

******************************
*** Outcomes ***
******************************
*** donor_2230 = inidcating donor between ages 22 and 30
*** numb_donor_2230 = number of years as donor ages 22-30
*** bet_kund_el_hush_rtjanst_2015 = paidfee or belong to a household that has paid the fee to the public broadcasting service
*** l_yyyy = voted in regional election in the year yyyy
*** r_yyyy = voted in the national election in the year yyyy
*** k_yyyy = votet in the municipal election in the year yyyy
*** any_vote_yyyy = voted in any of the three in year yyyy

**********************************************************************************
*** generate service branch ***
***********************************************************************************
count if utan_coherent!=.

gen army=(utan_coherent<20) if !missing(utan_coherent)

*** No KB. Indicator of highest rank with longest time in service ***
gen KB=btkdpos3=="6" if !missing(btkdpos3)

*** too long name ***
gen fee_2015=bet_kund_el_hush_rtjanst_2015

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/

*******************************************************************************
*** In Appendix E i restrict the analysis to Army units and further exclude the 
*** conscripts selected for the longest service duration ***
********************************************************************************

********************************************************************************
** Creating controls with means imputed and dummy variable indicating missing **
********************************************************************************
gen lngd2 = lngd if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(lngd) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace lngd2 = temp if lngd == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var lngd2 "Height"
drop temp
gen lngd_miss = (lngd == .)

gen finish_high_sch2 = finish_high_sch if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(finish_high_sch) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace finish_high_sch2 = temp if finish_high_sch==. & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var finish_high_sch2 "Finished High School"
drop temp
gen finish_high_sch_miss = (finish_high_sch == .)

gen fath_schyrs_mod2 = fath_schyrs_mod if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(fath_schyrs_mod) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace fath_schyrs_mod2 = temp if fath_schyrs_mod == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var fath_schyrs_mod2 "Father's Schoolyears"
drop temp
gen fath_schyrs_mod_miss = (fath_schyrs_mod == .)

gen moth_schyrs_mod2 = moth_schyrs_mod if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(moth_schyrs_mod) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace moth_schyrs_mod2 = temp if moth_schyrs_mod == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var moth_schyrs_mod2 "Mother's Schoolyears"
drop temp
gen moth_schyrs_mod_miss = (moth_schyrs_mod == .)

gen log_fath_ave_defl_totinc_C2 = log_fath_ave_defl_totinc_C if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(log_fath_ave_defl_totinc_C) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace log_fath_ave_defl_totinc_C2 = temp if log_fath_ave_defl_totinc_C == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var log_fath_ave_defl_totinc_C2 "(Log) Ave. Income Father"
drop temp
gen log_fath_ave_defl_totinc_C_miss = (log_fath_ave_defl_totinc_C == .)

gen log_moth_ave_defl_totinc_C2 = log_moth_ave_defl_totinc_C if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(log_moth_ave_defl_totinc_C) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace log_moth_ave_defl_totinc_C2 = temp if log_moth_ave_defl_totinc_C == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var log_moth_ave_defl_totinc_C2 "(Log) Ave. Income Mother"
drop temp
gen log_moth_ave_defl_totinc_C_miss = (log_moth_ave_defl_totinc_C == .)

gen muskkap2 = muskkap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(muskkap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace muskkap2 = temp if muskkap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var muskkap2 "Muscle Strength"
drop temp
gen muskkap_miss = (muskkap == .)

gen synkap2 = synkap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(synkap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace synkap2 = temp if synkap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var synkap2 "Sight Capacity"
drop temp
gen synkap_miss = (synkap == .)

gen fyskap2 = fyskap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(fyskap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace fyskap2 = temp if fyskap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var fyskap2 "Physical Capacity"
drop temp
gen fyskap_miss = (fyskap == .)

gen mass2 = mass if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(mass) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace mass2 = temp if mass == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var mass2 "Weight"
drop temp
gen mass_miss = (mass == .)

gen bodymass2 = bodymass if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(bodymass) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace bodymass2 = temp if bodymass == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var bodymass2 "BMI"
drop temp
gen bodymass_miss = (bodymass == .)

gen gkap2 = gkap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(gkap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace gkap2 = temp if gkap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var gkap2 "Cognitive Ability"
drop temp
gen gkap_miss = (gkap == .)

gen pf2 = pf if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(pf) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace pf2 = temp if pf == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var pf2 "Non-Cognitive Ability"
drop temp
gen pf_miss = (pf == .)


gen gckap2 = gckap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(gckap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace gckap2 = temp if gckap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var gckap2 "Spatial Ability"
drop temp
gen gckap_miss = (gckap == .)

gen gvkap2 = gvkap if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(gvkap) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace gvkap2 = temp if gvkap == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var gvkap2 "Verbal Ability"
drop temp
gen gvkap_miss = (gvkap == .)

gen intr2 = intr if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
egen temp = mean(intr) if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace intr2 = temp if intr == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var intr2 "Motivation"
drop temp
gen intr_miss = (intr == .)

** Health ***


gen hals_12 = hals_1 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
gen temp = 0 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace hals_12 = temp if hals_1 == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var hals_12 "Health Stat.=A"
drop temp
gen hals_1_miss = (hals_1 == .)

gen hals_22 = hals_2 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
gen temp = 0 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
replace hals_22 = temp if hals_1 == . & (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0
label var hals_22 "Health Stat.=B"
drop temp
gen hals_2_miss = (hals_2 == .)


********************************************************************************
*** Creating service trends in to-be closed and non-closed units ***
********************************************************************************
#delimit;
gen FB2004_coh_trend_ver2 = 1 if 
utan_coherent==13 	
| utan_coherent==11 	
| utan_coherent==12	
| utan_coherent==31	
| utan_coherent==28 	
| utan_coherent==24 	
| utan_coherent==25 	
| utan_coherent==23 	
| utan_coherent==37 	
| utan_coherent==26	
| utan_coherent==16 	
| utan_coherent==17 	
| utan_coherent==18  	
| utan_coherent==19 	
| utan_coherent==3;	

#delimit cr

replace FB2004_coh_trend_ver2=0 if FB2004_coh_trend_ver2==.

label define treatment 0 "Not closed" 1 "Closed"

label variable FB2004_coh_trend_ver2 "Closed base"
label values FB2004_coh_trend_ver2 treatment

tab FB2004_coh_trend_ver2  if (inrar > 2004 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0

tab FB2004_coh_ver2 if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20  & foreign==0

********************************************************************************
*** Figure E.1: Trends in the service rate of army conscripts by group of units 
********************************************************************************

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/graphs/army/

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0, by(inrar FB2004_coh_trend_ver2) clear : ci proportion stserv_ny2021
twoway (connected mean inrar if FB2004_coh_trend_ver2==1, lpattern(solid) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0, lpattern(solid) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0, lcolor(gray)), ///
ytitle(Share Started Service) xtitle(Planned Entry Year) legend(order(1 "(To-be) closed unit" 3 "Non closed unit")) name("trends_stserv_army_noKB", replace) nodraw  scheme(s1mono) ytick(0.35(0.05)0.95) yline(0.4(0.1)0.9, lpattern(dash) lcolor(gs12)) ylabel(0.4(0.1)0.9)
restore 

graph display trends_stserv_army_noKB
graph export "trends_stserv_army_noKB.png", replace
graph export "trends_stserv_army_noKB.tif", replace
graph export "trends_stserv_army_noKB.pdf", replace

********************************************************************************
*** First stage in the army sample ***
********************************************************************************
cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/army/

local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 

local 1 i.utan_coherent i.inrar 
local 2 i.utan_coherent i.inrar i.insk_quart_sif 
local 3 i.utan_coherent i.inrar i.insk_quart_sif `ind_controls'
local 4 i.utan_coherent i.inrar i.insk_quart_sif `ind_controls' `mother' `father'

set more off
eststo clear

forvalues n = 1(1)4 {

eststo: reg stserv_ny2021 FB2004_coh_ver2 ``n'' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20 & foreign==0 & army==1 & KB==0, cluster(base_inry_year)

test FB2004_coh_ver2
scalar fval=r(F)
estadd scalar fval

}

** Output with no controls shown **
esttab est* using "first_stage_stserv_army_noKB.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("fval F-statistic" "r2_a Adj. R-squared") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress noomitted nocon obslast keep(FB2004_coh_ver2)  replace label

esttab est* using "first_stage_stserv_army_noKB.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("fval F-statistic" "r2_a Adj. R-squared") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress noomitted nocon obslast keep(FB2004_coh_ver2)  replace label

********************************************************************************
*** The further restricted army sample ***
*** Exclude units with minor downward adjustments in number of conscripts ***
*** => The service rate in the group of non-closed units then is stable, ***
*** pre and post reform ***
********************************************************************************

gen restricted_control_group=(utan_coherent==7 | utan_coherent==14 | utan_coherent==8 | utan_coherent==9 | utan_coherent==10 | utan_coherent==15 )

********************************************************************************
*** Figure E.2: Trends in the service rate of army conscripts by group of units 
*** Furthe restricted army sample ***
********************************************************************************

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/graphs/army/

preserve
statsby if (inrar > 2000 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0 & age_mof_year<20 & foreign==0 & army==1 & KB==0 & restricted_control_group==0, by(inrar FB2004_coh_trend_ver2) clear : ci proportion stserv_ny2021
twoway (connected mean inrar if FB2004_coh_trend_ver2==1, lpattern(solid) lcolor(black) msymbol(T) mcolor(black))  ( rcap ub lb inrar if FB2004_coh_trend_ver2==1, lcolor(black)) ///
(connected mean inrar if FB2004_coh_trend_ver2==0, lpattern(solid) lcolor(gray) mcolor(gray)) (rcap ub lb inrar if FB2004_coh_trend_ver2==0, lcolor(gray)), ///
ytitle(Share Started Service) xtitle(Planned Entry Year) legend(order(1 "(To-be) closed unit" 3 "Non closed unit")) name("trends_stserv_army_noKB_r", replace) nodraw  scheme(s1mono) ytick(0.35(0.05)0.95) yline(0.4(0.1)0.9, lpattern(dash) lcolor(gs12)) ylabel(0.4(0.1)0.9)
restore 

graph display trends_stserv_army_noKB_r
graph export "trends_stserv_army_noKB_r.png", replace
graph export "trends_stserv_army_noKB_r.tif", replace
graph export "trends_stserv_army_noKB_r.pdf", replace

*********************************************************************************
** First Stage **
*********************************************************************************

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/army/


local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 

local 1 i.utan_coherent i.inrar 
local 2 i.utan_coherent i.inrar i.insk_quart_sif 
local 3 i.utan_coherent i.inrar i.insk_quart_sif `ind_controls'
local 4 i.utan_coherent i.inrar i.insk_quart_sif `ind_controls' `mother' `father'

set more off
eststo clear

forvalues n = 1(1)4 {

eststo: reg stserv_ny2021 FB2004_coh_ver2 ``n'' if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20 & foreign==0 & army==1 & KB==0 & restricted_control_group==0, cluster(base_inry_year)

test FB2004_coh_ver2
scalar fval=r(F)
estadd scalar fval

}

** Output with no controls shown **
esttab est* using "first_stage_stserv_army_noKB_r.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("fval F-statistic" "r2_a Adj. R-squared") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress noomitted nocon obslast keep(FB2004_coh_ver2)  replace label

esttab est* using "first_stage_stserv_army_noKB_r.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("fval F-statistic" "r2_a Adj. R-squared") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress noomitted nocon obslast keep(FB2004_coh_ver2)  replace label


********************************************************************************
*** Table E.1: Robustness checks, results using alternative sub-samples ***
********************************************************************************

cd /home/almdan/EoC/analysis/revising_citizenship/POBE_final/output/army/

	program iv_regress_r

	set more off
	
	syntax, dep_var(varname) endo_var(varname) instr(varname) controls1(varlist) controls2(varlist) save_as(name)

	eststo clear


eststo: ivregress 2sls `dep_var' i.utan_coherent i.inrar i.insk_quart_sif `controls1' `controls2' (`endo_var' = `instr') if (inrar > 2001 & insk_date_sif < td(23sep2004)) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20  & foreign==0 & army==1 & KB==0, cluster(base_inry_year)
estadd ysumm, mean

eststo: ivregress 2sls `dep_var' i.utan_coherent i.inrar i.insk_quart_sif `controls1' `controls2' (`endo_var' = `instr') if (inrar > 2001 & insk_date_sif < td(23sep2004) & inrar < 2006) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20  & foreign==0 & army==1 & KB==0, cluster(base_inry_year)
estadd ysumm, mean

eststo: ivregress 2sls `dep_var' i.utan_coherent i.inrar i.insk_quart_sif `controls1' `controls2' (`endo_var' = `instr') if (inrar > 2001 & insk_date_sif < td(23sep2004) & inrar < 2006) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20  & foreign==0 & army==1 & KB==0 & restricted_control_group==0, cluster(base_inry_year)
estadd ysumm, mean

eststo: ivregress 2sls `dep_var' i.utan_coherent i.inrar i.insk_quart_sif `controls1' `controls2' (`endo_var' = `instr') if (inrar > 2003 & insk_date_sif < td(23sep2004) & inrar < 2006) & inrar !=. & civserv_inskr==0 & old20==0  & age_mof_year<20  & foreign==0 & army==1 & KB==0 & restricted_control_group==0, cluster(base_inry_year)
estadd ysumm, mean


** Output with no controls shown **
esttab est1 est2 est3 est4 using "results/`save_as'.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("ymean Mean" "estimator Model") indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress mtitle("Army, 02-06" "Army, 02-05" "Army Sub-Sample, 02-05" "Army Sub-Sample, 04-05") nocon obslast keep(`endo_var')  replace label

esttab est1 est2 est3 est4 using "results/`save_as'.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("ymean Mean" "estimator Model")  indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif" ///
"Ind. Controls = muskkap2" "Parent Controls = fath*") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress nocon obslast keep(`endo_var')  replace label

** Output with controls shown **
esttab est1 est2 est3 est4  using "results/`save_as'_contr.rtf", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("ymean Mean" "estimator Model")  indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress mtitle("Army, 02-06" "Army, 02-05" "Army Sub-Sample, 02-05" "Army Sub-Sample, 04-05") nocon obslast replace label

esttab est1 est2 est3 est4  using "results/`save_as'_contr.tex", se starlevels(* 0.10 ** 0.05 *** 0.01) scalars("ymean Mean" "estimator Model")  indicate("Unit FE=*.utan_coherent" ///
"Plan Year FE=*.inrar" ///
"Conscr. Quarter FE=*.insk_quart_sif") ///
addnotes(Clustered standard errors at unit and plan entry year-level.) compress nocon obslast replace label

end
		
********************************************************************************

local ind_controls muskkap2 pf2 fyskap2 lngd2 mass2 synkap2 finish_high_sch2 intr2 gkap2 gvkap2 gckap2 hals_12 hals_22 muskkap_miss pf_miss fyskap_miss lngd_miss mass_miss synkap_miss finish_high_sch_miss intr_miss gkap_miss gvkap_miss gckap_miss hals_1_miss
local father fath_schyrs_mod2 fath_schyrs_mod_miss 
local mother moth_schyrs_mod2 moth_schyrs_mod_miss 

********************************************************************************

iv_regress_r, dep_var(numb_donor_2230) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(numb_donor_2230_army_noKB_r)

iv_regress_r, dep_var(donor_2230) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(donor_2230_army_noKB_r)

iv_regress_r, dep_var(r_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(r_2018_army_noKB_r)

iv_regress_r, dep_var(l_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(l_2018_army_noKB_r)

iv_regress_r, dep_var(k_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(k_2018_army_noKB_r)

iv_regress_r, dep_var(any_vote_2018) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(any_vote_2018_army_noKB_r)

iv_regress_r, dep_var(r_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(r_army_2010_noKB_r)

iv_regress_r, dep_var(l_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(l_army_2010_noKB_r)

iv_regress_r, dep_var(k_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(k_army_2010_noKB_r)

iv_regress_r, dep_var(any_vote_2010) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(any_vote_2010_army_noKB_r)

iv_regress_r, dep_var(fee_2015) endo_var(stserv_ny2021) instr(FB2004_coh_ver2) controls1(`ind_controls') controls2(`mother' `father') save_as(fee_2015_army_noKB_r)




